Taken from http://civicuk.com/cookie-law/deployment#scripts for reference.
Cookie Control allows you to run your analytics, or other scripts with little effort.
Cookie Control provides you with two events in the script that you copied from the generator.
The first one is called "onAccept:function(){}" and the second one "onCookiesAllowed:function(){}".
The "onAccept" event fires off the function defined when the user consents to allow cookies. This can be very useful: It that means you don't lose the first visit in your analytics tracking.
The "onCookiesAllowed" event fires off the function defined every time the user loads the page.
Google Analytics Example
You can use this example to deploy Google Analytics on your site: just add your own analytics code.
<script type="text/javascript">
function ccAddAnalytics(){
$.getScript('http://www.google-analytics.com/ga.js', function() {
var GATracker = _gat._createTracker('UA-XXXXXXX-X');
GATracker._trackPageview();
} );
};
</script>
Comments
Comment #1
buddaMight be able to do something using hook_js_alter(&$javascript) to manipulate the Google Analytics module output without directly amending the module.
Comment #2
buddaRuling is now saying analytics cookies are okay to carry on dropping on a visitor.
http://www.fourlakes.co.uk/2012/news/eu-cookie-law-twist/
http://econsultancy.com/uk/blog/9610-q-a-the-ico-s-dave-evans-on-eu-cook...
Comment #3
buddaThis facility has been implemented in a sub-module called 'cookie_googleanalytics' which can be found inside the cookiecontrol project directory. Enable it if ever needed.
Comment #4
AshleyF73 commentedI am finding with the Cookie Control for Google Analytics enabled, the Google cookies only show the next time I visit the website, which I assume means I am losing that initial site visit statistics?
Comment #5
buddaComment #6
artfulrobot commentedWith the google analytics module enabled I get zero stats - lost over a week of stats.
Comment #7
Anonymous (not verified) commentedI have also received zero stats since enabling the sub-module. Do we have to add something in the "On Cookie Accept" JavaScript box on the configuration page? The description text says: "JavaScript code to be executed when a visitor gives consent for the site to use cookies. Example use can be to trigger analytics code to record the initial page visit."
Comment #8
Anonymous (not verified) commentedComment #9
budda@jackocnr no nothing needs to be manually added to the on cookie accept box. In the page source you should be able to see googleanalytics listed in the functions to call on cookie accept.
The "On Cookie Accept" JavaScript box is to support other analytics which doesn't have a sub module available.
Comment #10
Anonymous (not verified) commentedThanks for your reply - fair enough.
But yer I can see the GA code is successfully being added to the function to call on cookie accept, but it seems like it's not being called! Any ideas why? I've now had to disable this module for all of my sites as clients are complaining about zero stats! As soon as I disable the GA submodule, they get stats again!
Do you think this might be a conflict with another module? Maybe jquery_update or something? If there's any more testing/information I can provide to help solve this issue I would be happy to do so.
Comment #11
kiwimind commentedI'm experiencing the same thing. Have just enable the CC and CCGA modules. When the cookies are accepted, no GA cookies drop, even when revisiting the site.
I will try and install the dev version and see if there's any change in that.
Comment #12
ecvandenberg commentedTested the 7.x-1.x-dev version of 2012-May-31 but also no GA cookies found.
Comment #13
Anonymous (not verified) commentedDitto - With CCGA module install regardles of acceptance no GA stats
Disable it works fine.
I have also notice that the popup always says 'i am happy with this' it never changes to 'Cookies are on' as per the example on the http://civicuk.com site.
is this jsut becuase its teh Drupal version not the raw js version?
Triangle does go green on click but text remains the same. but still no GA stats
Help!
Comment #14
TWH commentedI'm also experiencing the same issue - with the Cookie Control for Google Analytics module enabled on my site, I can see the google code on the source for a page, but no data is actually getting through. If I add the google tracking code directly into the html.tpl.php file at the bottom of the footer, it immediately sends stats through to the Analytics reports page.
Has anyone come up with a way around this yet so that the cookie control can still be used for ga?
Comment #15
buddaThe dev snapshot of the drupal module now uses the latest cookie control js to give the same UI as you have seen in the demo.
Comment #16
maltpress commentedUI is fine in dev now, certainly, but using Google Analytics submodule still stops any and all analytics.
The ruling does not say it's OK to drop analytics cookies on visitors regardless: it is being interpreted by some that giving full information in a privacy policy is enough to assume implied consent, assuming there are no other cookies which do fall under the legislation, but the ruling is still unclear and using something like this module muddies the water further; if this module is there the implication is that the user can opt in or out of *all* cookies, including GA ones, when that's clearly not the case. If all you have, cookie-wise, is GA cookies, then this module is useless: if you comply with the legislation you can't use GA so it does nothing, and if you go with the idea that GA cookies are fine you don't need it.
Is the only workaround to hard-code the GA code and wrap it in CookieControl.maySendCookies()?
[edit]
The issue appears to be that you can't call the asynchronous GA code within a function (i.e. where it's wrapping it in
ccAddAnalytics();in the sub-module). The workaround seems to be usingwindow['ga-disable-UA-xxxxxx-y'] = true;to disable cookies and then setting this to false, and calling the GA code again when you make a change (but not for subsequent page views) to re-enable them. I'm working on a patch but to be honest I'm not a Drupal dev, I'm a WordPress dev, and while it may work it's probably very untidy. Would appreciate a pair of more experienced eyes on it before I submit it anywhere.Comment #17
Rob Carriere commentedActually, I just ran into this bug myself, and it appears the problem is less annoying than that. :-)
The async script is perfectly happy being set up from a callback, but the variable _gaq must be global (i.e. window) scope in order for Analytics to work. So changing the code in the
ifstatement incookie_googleanalytics_js_alter()as follows:will make Google happy.
Comment #18
Rob Carriere commentedSorry, forgot to set status in the previous message.
Comment #19
buddaoh good spot Rob!
Comment #20
Rob Carriere commentedThanks.
Comment #21
Bestpoint commentedWhere can i find this?
I looked in the module but i cant find the cookie_googleanalytics_js_alter()
Comment #22
jonodunnett commentedI also can't find it. #17 appears to be a simple fix but needs a little bit more explanation about how to apply it, please.
Comment #23
taran2lAttached patch for #17.
Comment #24
buddaCommitted. Thanks Taran2l and Rob C.
Bestpoint & jonodunnett the function in question is part of the sub-module called cookie_googleanalytics.module which is part of this project.
Comment #25
taran2lI've found small issue with the provided patch today.
It creates the following JS code (due to double replacing):
Improved version is attached. Please review (patch against latest dev release).
P.S. You can preserve commit authorship by using:
git am < file.patch